package com.example.view.module.conflict.nestedscroll_a;

import android.util.Log;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;

import com.example.common.base.AbsActivity;
import com.example.view.R;
import com.example.view.databinding.ActConflictNestedViewpagerBinding;
import com.example.view.module.conflict.common.RecyclerViewFragment;
import com.example.view.module.conflict.common.ViewPagerAdapter;
import com.google.android.material.tabs.TabLayout;
import com.google.android.material.tabs.TabLayoutMediator;

import java.util.ArrayList;
import java.util.List;

public class NestedViewPagerActivity extends AbsActivity<ActConflictNestedViewpagerBinding> {
    @Override
    protected int getLayoutId() {
        return R.layout.act_conflict_nested_viewpager;
    }

    @Override
    protected void main() {
        ViewPagerAdapter pagerAdapter = new ViewPagerAdapter(this, getPageFragments());
        mBinding.viewpagerView.setAdapter(pagerAdapter);
        // binding.comboContentView.setOffscreenPageLimit(1);
        final String[] labels = new String[]{"linear", "scroll", "recycler"};
        new TabLayoutMediator(mBinding.tablayout, mBinding.viewpagerView, new TabLayoutMediator.TabConfigurationStrategy() {
            @Override
            public void onConfigureTab(@NonNull TabLayout.Tab tab, int position) {
                tab.setText(labels[position]);
            }
        }).attach();
        mBinding.swipeRefresh.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
            @Override
            public void onRefresh() {
                Log.e(TAG, "Refresh started...");
                mBinding.getRoot().postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        mBinding.swipeRefresh.setRefreshing(false);
                    }
                },1000);
            }
        });
    }

    @Override
    protected void initListener() {

    }

    private List<Fragment> getPageFragments() {
        List<Fragment> data = new ArrayList<>();
        data.add(new RecyclerViewFragment());
        data.add(new RecyclerViewFragment());
        data.add(new RecyclerViewFragment());
        return data;
    }
}
